#!/usr/bin/env python3
import logging
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
from scapy.all import *
from random import randint
def scapy_ping_one(host):
    id_IP = randint(1,65535)#随机产生IP位的id
    id_ICMP = randint(1,65535)#随机产生ICMP位的id
    seq_ping = randint(1,65535)#随机产生序列号
    packet = IP(dst=host,ttl=64,id=id_IP)/ICMP(id=id_ICMP,seq=seq_ping)/b'sirian welcome U'
    ping = sr1(packet,timeout=2,verbose=False)
    #ping.show()
    if ping:#如果有响应信息
        os._exit(3)#自定义退出码
if __name__ == '__main__':
    import sys
    host = sys.argv[1]
    scapy_ping_one(host)
    
